<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Session Plugin
 *
 * Read and write session data
 *
 * @package        925CMS
 * @author        925CMS Dev Team
 * @copyright    Copyright (c) 2008 - 2011, 925CMS
 *
 */
class Plugin_Template extends Plugin
{
    /**
     * Data
     *
     * Loads a template partial
     *
     * Usage:
     * {cms:template:partial name="sidebar"}
     *
     * @return    array
     */
    function partial()
    {
        $name = $this->attribute('name');

        $data =& $this->load->_ci_cached_vars;

        return isset($data['template']['partials'][$name]) ? $data['template']['partials'][$name] : '';
    }

    /**
     * Checks for existance of a partial
     *
     * Usage:
     * {cms:template:has_partial name="sidebar"}
     *    <p>Hello admin!</p>
     * {/cms:template:has_partial}
     *
     * @return    array
     */
    function has_partial()
    {
        $name = $this->attribute('name');

        $data =& $this->load->_ci_cached_vars;

        if (isset($data['template']['partials'][$name])) {
            return $this->content() ? array(array('partial' => $data['template']['partials'][$name])) : TRUE;
        }

        return $this->content() ? array() : '';
    }

    /**
     * Check for the existance of breadcrumbs
     *
     * Usage:
     * {if '{cms:template:has_breadcrumbs}'}
     *    {cms:template:breadcrumbs}
     *        {if '{cms:uri}'}
     *            {cms:url:anchor segments='{cms:uri}' title='{cms:name}'}
     *        {else}
     *            {cms:name}
     *        {/if}
     *    {/cms:template:breadcrumbs}
     * {/if}
     * @return    bool
     */
    function has_breadcrumbs()
    {
        $data =& $this->load->_ci_cached_vars;

        $crumbs = $data['template']['breadcrumbs'];

        return !empty($crumbs) ? TRUE : FALSE;
    }

    function __call($foo, $arguments)
    {
        $data =& $this->load->_ci_cached_vars;

        return isset($data['template'][$foo]) ? $data['template'][$foo] : NULL;
    }
}

/* End of file template.php */
